namespace KinonekoSoftware.CodariaDB.Documents.DataParts.Basics
{
    public abstract class CompositeItem : RootObject, ICloneable<CompositeItem>
    {
        private string _name;
        private string _Metadata;
        private bool   _isRemovable;

        public abstract CompositeItem Clone();
        public abstract Variant GetVariant(string documentID);

        /// <summary>
        /// 
        /// </summary>
        public string AsString
        {
            get
            {
                var self = this;

                if (self is CompositeProperty cp)
                {
                    return cp.Value;
                }

                if (self is CompositeParagraph cp2)
                {
                    return cp2.Value;
                }

                return ((CompositeToggleSwitch)self).Value.ToString();
            }
        }

        public bool AsBoolean
        {
            get
            {
                var self = this;

                if (self is CompositeToggleSwitch cp)
                {
                    return cp.Value;
                }

                return false;
            }
        }

        public bool IsEditable { get; set; }

        /// <summary>
        /// 获取或设置 <see cref="IsRemovable"/> 属性。
        /// </summary>
        public bool IsRemovable
        {
            get => _isRemovable;
            set => SetValue(ref _isRemovable, value);
        }

        public string Metadata
        {
            get => _Metadata;
            set => SetValue(ref _Metadata, value);
        }

        public string Name
        {
            get => _name;
            set => SetValue(ref _name, value);
        }
        
        [Runtime]
        [BsonIgnore]
        public Action<CompositeItem> OnValueChanged { get; set; }
    }
}